package com.xiaoma.tpo.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoma.tpo.dao.ForcastDao;
import com.xiaoma.tpo.dto.ForcastDto;
import com.xiaoma.tpo.dto.ForcastQuestionDto;
import com.xiaoma.verbal.dao.FctForecastDao;
import com.xiaoma.verbal.domain.FctForecast;
import com.xiaoma.verbal.domain.FctQuestion;
import com.xiaoma.verbal.utils.DateUtil;

@Service
public class ForcastService {

	@Autowired
	private FctForecastDao fctForecastDao;
	
	@Autowired
	private ForcastDao forcastDao;
	
//	public List<ForcastDto> findAllForcast() {
//		
//		return forcastDao.findAllForcast();
//	}
	//旧的方法
    public List<ForcastDto> findAllForcast() {
		
		List<FctForecast> list = fctForecastDao.findTop3();
		List<ForcastDto> forcastList = new ArrayList<ForcastDto>();
		for(FctForecast fct : list) {
			ForcastDto forcastDto = new ForcastDto();
			forcastDto.setGroupIndex(fct.getId());
			forcastDto.setGroupName(DateUtil.dateToStr(fct.getTimeRange1(), "yyyy年MM月dd日"));
			List<ForcastQuestionDto> questions = forcastDao.findByFctId(fct.getId());
			forcastDto.setForcastQuestions(questions);
			forcastList.add(forcastDto);
		}
		return forcastList;
	}
    //新
	public List<FctQuestion> findAllForcastNew(Integer id) {
		
		List<FctQuestion> list = fctForecastDao.findAllForcastNew(id);
		return list;
	}
}
